﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="User.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the User type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Model
{
    using System.ComponentModel;

    /// <summary>
    /// Defines the <seealso cref="User"/> type.
    /// </summary>
    public class User : ModelBase, IDataErrorInfo
    {
        /// <summary>
        /// Backing field for User name
        /// </summary>
        private string _userName;

        /// <summary>
        /// Backing field for password
        /// </summary>
        private string _password;

        /// <summary>
        /// Backing field for error
        /// </summary>
        private string _error;

        /// <summary>
        /// Gets or sets the username.
        /// </summary>
        /// <value>
        /// The username.
        /// </value>
        public string UserName
        {
            get
            {
                return _userName;
            }

            set
            {
                if (_userName != value)
                {
                    _userName = value;
                    RaisePropertyChangedEvent("UserName");
                }
            }
        }

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>
        /// The password.
        /// </value>
        public string Password
        {
            get
            {
                return _password;
            }

            set
            {
                if (_password != value)
                {
                    _password = value;
                    RaisePropertyChangedEvent("Password");
                }
            }
        }

        #region IDataErrorInfo Members

        /// <summary>
        /// Gets or sets an error message indicating what is wrong with this object.
        /// </summary>
        /// <returns>An error message indicating what is wrong with this object. The default is an empty string ("").</returns>
        public string Error
        {
            get
            {
                return _error;
            }

            set
            {
                _error = value;
            }
        }

        /// <summary>
        /// Gets the error message for the property with the given name.
        /// </summary>
        /// <param name="columnName">Column name to get</param>
        /// <returns>The error message for the property. The default is an empty string ("").</returns>
        public string this[string columnName]
        {
            get
            {
                if (columnName == "UserName")
                {
                    if (string.IsNullOrEmpty(UserName))
                    {
                        _error = "UserName cannot be empty";
                        return "UserName cannot be empty";
                    }
                }

                if (columnName == "Password")
                {
                    if (string.IsNullOrEmpty(Password))
                    {
                        _error = "Password cannot be empty";
                        return "Password cannot be empty";
                    }
                }

                return string.Empty;
            }
        }

        #endregion IDataErrorInfo Members
    }
}